<template>
  <div class="video-container">
    <div class="video-top">
      <video id='my-video' :src="videoList[current].url" autoplay @error="binderror" @ended="bindended"></video>
      <div class="movie-info">
        <div class="movie-info-left">
          <div class="movie-info-name">{{movieData.movieName}}</div>
          <div v-if="movieData.globalReleased">猫眼评分 <span class="yellow">{{movieData.sc}}</span></div>
          <div v-else><span class="yellow">{{movieData.wish}}</span> 想看</div>
          <div>{{movieData.release}}</div>
        </div>
        <div class="movie-info-right">
          <div v-if="movieData.showst === 1" class="btn want-see">想看</div>
          <div v-if="movieData.showst === 3" class="btn">购票</div>
          <div v-if="movieData.showst === 4" class="btn pre-sale">预售</div>
        </div>
      </div>
    </div>
    <dividerBox />
    <div class="about-list">
      <div class="list-title">播放列表({{videoList.length}})</div>
      <div class="list-item" v-for="(item, index) in videoList" :key="index">
        <div class="item-img">
          <img :src="item.img" alt="">
          <div class="current-style" v-if="current === index">播放中</div>
        </div>
        <div class="list-name">{{item.name}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import dividerBox from '../../components/dividerBox.vue'
export default {
  data() {
    return {
      movieData: null,
      videoList: [],
      current: 0
    }
  },
  components: {
    dividerBox
  },
  onLoad(option) {
    // 获取页面跳转传参
    this.movieData = JSON.parse(option.params);
    console.log(this.movieData);
    // 因为没有获取相关video列表的api，所以只能模拟写死数据，后期可以多拿去一些数据，做一个随机渲染，更像真实数据
    this.videoList = [
      {...this.movieData.video},
      {
        img: 'https://obj.pipi.cn/friday/ed42b04ecc3a74506941131041e164e9.jpg',
        name: '丁泽仁友情提示：《贝肯熊2:金牌特工》7月23日上映',
        url: 'https://vod.pipi.cn/fec9203cvodtransbj1251246104/5ad93bd23701925921295897266/v.f42905.mp4',
      }, {
        img: 'https://p0.meituan.net/movie/f87a64c44eaa0216d541fb6f013eba4123888.jpg',
        name: '小美好”版终极预告片 今年最减龄减压的青春片！',
        url: 'https://maoyan.meituan.net/movie/videos/854x48041256160be8947b182921987f3e9da4c.mp4',
      }, {
        img: 'http://p0.meituan.net/moviemachine/bb328a0c128f94d87409397812d24f3a673103.png',
        name: '《俑之城》终极预告报告：只有我能定义我是谁！7月9日，震撼上映！',
        url: 'https://vod.pipi.cn/fec9203cvodtransbj1251246104/debce5ff3701925920310458843/v.f42905.mp4',
      }
    ]
  },
  methods: {
    // 视频播放错误处理
    binderror() {
      wx.showToast({
        title: '播放错误', //提示的内容,
        icon: 'none' //图标
      });
      if (this.current === this.videoList.length) {
        this.current = 0
      } else {
        this.current++
      }
    },
    // 视频播结束时触发的事件
    bindended() {
      if (this.current === this.videoList.length) {
        this.current = 0
      } else {
        this.current++
      }
    }
  }
}
</script>

<style lang="less" scoped>
.video-container {
  width: 100vw;
  .video-top {
    width: 100%;
    video {
      width: 100%;
    }
    .movie-info {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 30rpx;
      font-size: 26rpx;
      color: #666;
      line-height: 50rpx;
      .movie-info-left {
        .movie-info-name {
          font-size: 38rpx;
          color: #333;
        }
      }
    }
  }
  .about-list {
    .list-title {
      padding: 30rpx;
      border-bottom: 1px solid #f5f5f5;
    }
    .list-item {
      display: flex;
      align-items: flex-start;
      border-bottom: 1px solid #f5f5f5;
      padding: 30rpx;
      .item-img {
        width: 220rpx;
        height: 124rpx;
        position: relative;
        img {
          flex-shrink: 0;
          width: 220rpx;
          height: 124rpx;
        }
        .current-style {
          position: absolute;
          bottom: 8rpx;
          left: 8rpx;
          font-size: 24rpx;
          color: #fff;
        }
      }

      .list-name {
        flex: 1;
        margin-left: 30rpx;
        word-break: break-all;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        font-size: 30rpx;
        color: #666;
      }
    }
  }
}
.movie-info-right {
  .btn {
    width: 94rpx;
    height: 56rpx;
    line-height: 56rpx;
    text-align: center;
    box-sizing: border-box;
    background-color: #f03d37;
    color: #fff;
    border-radius: 8rpx;
    white-space: nowrap;
    font-size: 24rpx;
    border: none;
  }
  .want-see {
    background-color: #faaf00;
  }
  .pre-sale {
    background-color: #3c9fe6;
  }
}
.yellow {
  color: #ffc600;
  font-size:32rpx;
}
</style>